#ifndef SERVER_H
#define SERVER_H

#include <QObject>
#include <iostream>
#include <stdlib.h>
#include <strings.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <memory.h>
#include <unistd.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <qthread.h>

#include <signal.h>

#define PORT    11910   //定义通信端口
#define BACKLOG 5       //定义侦听队列长度
#define buflen  1024
#define SERVERIP  "127.0.0.1"

using namespace std;

class server : public QObject
{
    Q_OBJECT
    enum cmdtype
    {
        CMD_REJEST,
        CMD_LOGIN,
        CMD_SENDMESSAGE
    };

    struct data
    {
        int sender;
        int receiver;
        cmdtype cmd;
        char  buf[1024];
    };
public:
    explicit server(QObject *parent = 0);
    static server* inst();
    void registServer();
    int closeServer();

private:
    void handle();
    void sendMesssage(data d);

signals:

public slots:

private:
    int ss;  //ss为服务器socket描述符
    int sc;  //sc为某一客户端通信socket描述符
    static server* s_inst;
};

#endif // SERVER_H
